package com.black.utils.commons.network;

import lombok.extern.slf4j.Slf4j;

/**
 * @author ylx
 */
@Slf4j
public abstract class ServerThread extends Thread {
    protected final String receive() throws Exception {
        log.debug("server: {};receive message from client", this.getClass().getSimpleName());
        return receiveMsg();
    }

    protected final String handle(String msg) {
        log.debug("server: {};handle message: {}", this.getClass().getSimpleName(), msg);
        return handleMsg(msg);
    }

    protected final void response(String response) throws Exception {
        log.debug("server: {};response message: {}", this.getClass().getSimpleName(), response);
        responseMsg(response);
    }

    protected abstract String receiveMsg() throws Exception;

    protected String handleMsg(String msg) {
        return "Hello Client";
    }

    protected abstract void responseMsg(String response) throws Exception;
}
